from fastapi import APIRouter
from pydantic import BaseModel,Field, validator
from datetime import date
from typing import Union
request_body = APIRouter()

class Address(BaseModel):
    street: str
    city: str
    country: str

class User(BaseModel):
    name: str = "root"
    age: int = Field(default=18,gt=18,lt=80)
    birthday: Union[date,None] = Field(default=None)
    friends: list[int] = Field(default=[])
    address: Address 
    
    @validator("name")
    def name_validator(cls,v):
        assert v.isalpha(),"name must be alphabetic"
        return v


@request_body.post("/items/")
def create_item(user: User):
    print(user.dict())
    return user




